www.gusucode.com > VC 圆形时钟程序(实现指针移动与修改时间)-源码程序 > VC 圆形时钟程序(实现指针移动与修改时间)-源码程序/code/Test13_4Doc.cpp
// Test13_4Doc.cpp : implementation of the CTest13_4Doc class // Download by http://www.NewXing.com #include "stdafx.h" #include "Test13_4.h" #include <math.h> #include "Test13_4Doc.h" #define PI 3.1415926 #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTest13_4Doc IMPLEMENT_DYNCREATE(CTest13_4Doc, CDocument) BEGIN_MESSAGE_MAP(CTest13_4Doc, CDocument) //{{AFX_MSG_MAP(CTest13_4Doc) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTest13_4Doc construction/destruction CTest13_4Doc::CTest13_4Doc() { // TODO: add one-time construction code here } CTest13_4Doc::~CTest13_4Doc() { } BOOL CTest13_4Doc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here this->m_Rect = CRect(100,100,400,400); this->m_org = this->m_Rect.CenterPoint(); this->m_centerRect = CRect(m_Rect.TopLeft().x+140, m_Rect.TopLeft().y+140, m_Rect.BottomRight().x-140, m_Rect.BottomRight().y-140); CTime time = CTime::GetCurrentTime(); this->m_hour = time.GetHour(); this->m_min = time.GetMinute(); this->m_sec = time.GetSecond(); //设置时钟指针的终点位置 // this->M_MoveClockHands(); //设置指针的长度 hLen = 80; mLen = 100; sLen = 120; // (SDI documents will reuse this document) return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CTest13_4Doc serialization void CTest13_4Doc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CTest13_4Doc diagnostics #ifdef _DEBUG void CTest13_4Doc::AssertValid() const { CDocument::AssertValid(); } void CTest13_4Doc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CTest13_4Doc commands void CTest13_4Doc::m_TickAdd() { this->m_sec ++; if(this->m_sec == 60) { this->m_min ++; this->m_sec = 0; } if(this->m_min == 60) { this->m_hour ++; this->m_min = 0; } if(this->m_hour >= 12) { this->m_hour -= 12; } } void CTest13_4Doc::M_MoveClockHands() { int px, py; double degree; //设置秒针的终点坐标 degree = this->m_sec * 6 - 90; px = cos((degree/180.0)*PI)* sLen + 250; py = sin((degree/180)*PI)* sLen + 250; this->m_secEndPoint.x = px; this->m_secEndPoint.y= py; //设置分针的终点坐标 degree = this->m_min * 6 - 90; px = cos((degree/180.0)*PI) * mLen + 250; py = sin((degree/180)*PI) * mLen + 250; this->m_minEndPoint.x = px; this->m_minEndPoint.y = py; //设置时针的终点坐标 degree = this->m_hour * 30 - 90; px = cos((degree/180.0)*PI) * hLen + 250; py = sin((degree/180.0)*PI) * hLen + 250; this->m_hourEndPoint.x = px; this->m_hourEndPoint.y = py; }